package com.example.leetcode;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class TestHW {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nums = scanner.nextLine().split(" ");
        int[] lists = new int[nums.length];
        int c=0;
        for (String s:nums){
            lists[c]=Integer.valueOf(s);
            c++;
        }

         Arrays.sort(lists);
         int count =Integer.valueOf(scanner.nextLine());
         scanner.close();
         int sum =0;
         if (nums.length<3){
             sum=-1;
         }
        if (Integer.valueOf(lists[0])>count){
            sum=-1;
        }

             int countNum=0;
             for (int n:lists){
                 int s =n;
                 count=count-s;
                 if (count<0){
                     break;
                 }
                 sum=sum+s;
                 countNum++;
             }
             if (countNum<3){
                 sum=-1;
             }

        System.out.println(sum);
    }
}
